package cn.com.sbell.vss.csg.vap;

import javax.servlet.http.HttpServletRequest;

import cn.com.sbell.vss.ICommander;
import cn.com.sbell.vss.Response;
import cn.com.sbell.vss.csg.vap.bean.AlarmMessage;
import cn.com.sbell.vss.csg.vsclient.util.AlarmDispatchGroup;
import cn.com.sbell.vss.csg.vsclient.util.PropertiesHolder;

public class RaiseAlarm implements ICommander {

	public Response execute(HttpServletRequest request) {
		PropertiesHolder holder = PropertiesHolder.getInstanceFromRequest(request);
		
		AlarmMessage alarmMsg = new AlarmMessage();
		alarmMsg.setAlarmType(holder.getStrProperty("alarmType"));
		alarmMsg.setEventType(holder.getIntProperty("eventType"));
		alarmMsg.setAlarmCode(holder.getStrProperty("alarmCode"));
		alarmMsg.setCameraNumber(holder.getIntProperty("cameraNumber"));
		alarmMsg.setChannelNumber(holder.getIntProperty("channelNumber"));
		alarmMsg.setDiskNumber(holder.getIntProperty("diskNumber"));
		alarmMsg.setData(holder.getStrProperty("data"));
		alarmMsg.setDeviceId(holder.getStrProperty("deviceId"));
		alarmMsg.setEliminated(holder.getBoolProperty("eliminated") == null ? false : holder.getBoolProperty("eliminated").booleanValue());
		alarmMsg.setServerIp(request.getRemoteAddr());
//		added vondart for AH
		alarmMsg.setServerType(holder.getStrProperty("serverType"));
		if(!(AlarmMessage.SERVER_AH.equalsIgnoreCase(alarmMsg.getServerType())))
		{
		if(alarmMsg.getCameraNumber() != null){
			alarmMsg.setServerType("CAM");
		}else{
			alarmMsg.setServerType("VS");
		}
		}
		AlarmDispatchGroup.getAlarmDispatchGroup().addMessage(alarmMsg);
		
		Response response = Response.createResponse(request);
		response.setParameters(null);
	
		return response;
	}

}
